/**
 * Bestpay.com.cn Inc.
 * Copyright (c) 2011-2019 All Rights Reserved.
 */
package com.suxiaoxiao.springbootlearn.java.optional;

import java.util.Optional;

/**
 * desc
 *
 * @author zhaorongzhang
 * @version OptionalTest.java, v 0.1 2019/12/26 2:06 下午 zhaorongzhang Exp $$
 */
public class OptionalTest {

    public static void main(String[] args) {

        Student student = new Student();
        student.setName("赵融璋");

        Student student1 = null;

        // 如果是 null 会抛出空指针异常
//        Optional<Student> student1 = Optional.of(student);

        // 即使是 null 也不会抛异常 一般使用这个
        Optional<Student> student2 = Optional.ofNullable(student);
        Optional<Student> student3 = Optional.ofNullable(student1);

        System.out.println(student2.orElse(null));
        System.out.println(student3.orElse(null));

    }

}